home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / doc / signal.doc < prev    next >
Text File  |  1993-07-05  |  3KB  |  149 lines

  1.  
  2.     SIGNAL.DOC (c)Copyright 1990, Matthew Dillon, All Rights Reserved
  3.  
  4. TABLE OF CONTENTS
  5.  
  6. c.lib/signal/signal
  7. c.lib/signal/raise
  8.  
  9.  
  10. signal/signal                        signal/signal
  11.  
  12.    NAME
  13.     signal    - set a signal vector for a signal
  14.  
  15.    SYNOPSIS
  16.     typedef void (*__sigfunc)(int);
  17.  
  18.     __sigfunc oldfunc = signal(signo, newfunc)
  19.     int signo;
  20.     __sigfunc newfunc;
  21.  
  22.    FUNCTION
  23.     signal() sets a signal vector function for a given signal number as
  24.     defined in <signal.h> and returns the previously set function.
  25.  
  26.     currently only SIGINT causes any semi-asynchronous action to occur.
  27.     You may pass newfunc as your own signal function or one of:
  28.  
  29.     SIG_ERR     error (exit program)
  30.     SIG_DFL     default (for break, normal operation)
  31.     SIG_IGN     ignore signal (for break, ^C is now ignored)
  32.  
  33.     when a signal occurs, the signal is set back to its default
  34.     condition before the handler is called.  Thus, if you are allowing
  35.     multiple signals to occur you MUST restore the signal vector
  36.     with signal() from your signal handler before it returns.
  37.  
  38.    NOTE
  39.     signal()s on the Amiga are not truely asynchronous.  Currently
  40.     ^C is detected during stdio calls only.  No other signal is
  41.     implemented though you *can* modify any signal vector 0 to 31
  42.     and raise it with the raise() call.
  43.  
  44.     Early versions of DICE, including quite possibly this version,
  45.     do not understand complex type declarations containing
  46.     procedural types.  Thus, you may have to get around the problem
  47.     by building up a complex procedural type with typedefs.
  48.  
  49.     Unlike onbreak(), a signal function returns no value.
  50.  
  51.    EXAMPLE
  52.     #include <signal.h>
  53.  
  54.     void brkfunc(int);
  55.  
  56.     main()
  57.     {
  58.         short i;
  59.  
  60.         puts("The following is unbreakable");
  61.         sleep(1);
  62.         signal(SIGINT, SIG_IGN);
  63.         for (i = 0; i < 100; ++i)
  64.         printf("1 %d\n", i);
  65.  
  66.         puts("The following may be broken out of");
  67.         puts("with a cute message");
  68.         sleep(1);
  69.         signal(SIGINT, brkfunc);
  70.         for (i = 0; i < 100; ++i)
  71.         printf("2 %d\n", i);
  72.  
  73.         puts("The following may be broken out of");
  74.         sleep(1);
  75.         signal(SIGINT, SIG_DFL);
  76.         for (i = 0; i < 100; ++i)
  77.         printf("3 %d\n", i);
  78.         puts("Hey! You never hit ^C!  What kind of test is this!");
  79.         return(0);
  80.     }
  81.  
  82.     void
  83.     brkfunc(int signo)
  84.     {
  85.         printf("signo %d occured, exiting\n", signo);
  86.         exit(1);
  87.     }
  88.  
  89.    INPUTS
  90.     int      signo;    signal to modify, usually SIGINT
  91.     __sigfunc newfunc;    signal function or SIG_ERR, SIG_DFL, SIG_IGN
  92.  
  93.    RESULTS
  94.     __sigfunc oldfunc;    previous signal function
  95.  
  96.    SEE ALSO
  97.     raise
  98.  
  99.  
  100. signal/raise                        signal/raise
  101.  
  102.    NAME
  103.     raise  - raise a signal (cause an 'interrupt' synchronously)
  104.  
  105.    SYNOPSIS
  106.     int r = raise(signo);
  107.     int signo;
  108.  
  109.    FUNCTION
  110.     raise() causes a signal to occur and the appropriate action to be
  111.     taken.    raise() returns 0 on success, -1 if the signo is invalid
  112.     (outside the range of allowed signals).
  113.  
  114.     when you raise a signal, the signal is set back to its default
  115.     vector before the handler is called.  Thus, if you are allowing
  116.     multiple signals to occur you MUST restore the signal vector with
  117.     signal() from your signal handler before it returns.
  118.  
  119.    EXAMPLE
  120.     /*
  121.      *  prints the numbers 0 to 99, except only gets to 50 because
  122.      *  we 'cause' a ^C.
  123.      */
  124.  
  125.     #include <signal.h>
  126.  
  127.     main()
  128.     {
  129.         short i;
  130.  
  131.         for (i = 0; i < 100; ++i) {
  132.         printf("i = %d\n", i);
  133.         if (i == 50)
  134.             raise(SIGINT);
  135.         }
  136.         return(0);
  137.     }
  138.  
  139.    INPUTS
  140.     int      signo;    signal to cause
  141.  
  142.    RESULTS
  143.     int      r;        0 on success, -1 if signo is out of range.
  144.  
  145.    SEE ALSO
  146.     signal
  147.  
  148.  
  149.